/**
 * 操作用户相关信息
 */
import { defineStore } from "pinia";
import { IUserInfo, IUserInfoActions,  IUserInfoState, IUserInfoGetter } from "../models/userInfoModel";
import { useKeys } from '@/utils/useKeys'
import { useLocalStorage } from "@/utils";
const key =useKeys()
export const useUserStore = defineStore<string,IUserInfoState,IUserInfoGetter,IUserInfoActions>('userStore',{
   state:():IUserInfoState =>{
    return {
       userInfo:null
    }
   },
   getters:{
    GetUsers(user) {
       if (user.userInfo) {
        return user.userInfo
       } else {
         return useLocalStorage.getSecretObject<IUserInfo>(key.USER_INFO)
       }
    },
   },
   actions:{
     setUsers(user) {
       useLocalStorage.setSecretObject<IUserInfo>(key.USER_INFO,user)
     },
     clearUsers() {
         useLocalStorage.remove(key.USER_INFO)
     }
   }

})